package com.itzjc.utils;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * TODO
 *
 * @className: BaseCache
 * @date: 2021-06-04 22:01
 **/
@Component
public class BaseCache {

    private Cache<String, Object> tenMinuteCache = CacheBuilder.newBuilder()
            //初始缓存容量
            .initialCapacity(10)
            //最大容量
            .maximumSize(100)
            //允许同时写入的线程数量
            .concurrencyLevel(5)
            //过期时间
            .expireAfterWrite(600, TimeUnit.SECONDS)
            //记录缓存命中率
            .recordStats()
            .build();

    public Cache<String, Object> getTenMinuteCache() {
        return tenMinuteCache;
    }

    public void setTenMinuteCache(Cache<String, Object> tenMinuteCache) {
        this.tenMinuteCache = tenMinuteCache;
    }
}
